package study.mq.rocketmq.consumer.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(topic = "test",
        consumerGroup = "test_group",
        consumeThreadNumber = 20,
        consumeTimeout = 1)
public class _01_Consumer implements RocketMQListener<String>, RocketMQPushConsumerLifecycleListener {

    @Override
    public void onMessage(String message) {
        //ThreadUtil.sleep(5, TimeUnit.SECONDS);
        log.info(">>>>>> {}", message);
    }

    @Override
    public void prepareStart(DefaultMQPushConsumer consumer) {
        //最大重试次数，默认 16
        consumer.setMaxReconsumeTimes(10);
    }
}
